import json
from calc_loss_001 import calculate_loss



# 使用示例
if __name__ == "__main__":
    try:
        loss_calc_payload = {
            "stockNo": "300356",  # 股票代码
            "stockName": "光一退",  # 股票名称
            "brokerName": "中信证券",  # 券商名称
            "stockBroker": "600030"  # 券商代码
        }

        transactions = [
            {
                "stockNo": "300356",
                "operationTime": "2023-06-20",
                "direction": "buy",
                "price": 2.12,
                "qty": 500,
                "amount": 1060
            },
            {
                "stockNo": "300356",
                "operationTime": "2023-06-26",
                "direction": "buy",
                "price": 2.02,
                "qty": 500,
                "amount": 1010
            },
            {
                "stockNo": "300356",
                "operationTime": "2023-07-05",
                "direction": "sell",
                "price": 1.50,
                "qty": 1000,
                "amount": 1500
            }
        ]

        results = calculate_loss(loss_calc_payload=loss_calc_payload, transactions=transactions)
        print("盈亏试算流程完成，结果：")
        for step, result in results.items():
            print(f"\n{step}:", json.dumps(result, indent=2, ensure_ascii=False))
    except Exception as e:
        print(f"执行过程中出现错误: {str(e)}")

"""

测试结果：符合预期
测算结果：status=10 成功，预期损失金额=0  实际损失金额estimate_loss_ammount=0

SELECT * from stock_loss_caculation where id=885428376221782016;
SELECT * from stock_loss_caculation_detail where loss_id = 885428376221782016;
"""
